import { request } from '@inbiz/utils';

/**
 * 查询分组列表
 * @param params
 */
export async function getStaticGroupList(appId: string) {
  return request(
    `/inbiz/api/services/modelengine/v${InbizConfig.API_VERSION}/dictGroup?appId=${appId}`,
  );
}

/**
 * 保存分组（添加）
 * @param params
 */
export async function saveStaticGroupList(params: { appId: string; name: string }) {
  return request(`/inbiz/api/services/modelengine/v${InbizConfig.API_VERSION}/dictGroup`, {
    method: 'POST',
    data: params,
  });
}

/**
 * 修改分组
 * @param params
 */
export async function editStaticGroupList(params: { key: string; name: string; appId: string }) {
  return request(
    `/inbiz/api/services/modelengine/v${InbizConfig.API_VERSION}/dictGroup?appId=${params.appId}`,
    {
      method: 'PUT',
      data: params,
    },
  );
}

/**
 * 删除分组
 * @param params
 */
export async function delStaticGroupList(params: { appId: string; key: string }) {
  return request(
    `/inbiz/api/services/modelengine/v${InbizConfig.API_VERSION}/dictGroup?appId=${params.appId}&key=${params.key}`,
    {
      method: 'DELETE',
    },
  );
}

/**
 * 查看具体分组字典
 * @param params
 */
export async function getStaticDataList(params: { appId: string; groupKey: string }) {
  return request(
    `/inbiz/api/services/modelengine/v${InbizConfig.API_VERSION}/dictData?appId=${params.appId}&groupKey=${params.groupKey}`,
  );
}

/**
 * 保存当前分组字典
 * @param params
 */
export async function saveStaticDataList(params: {
  appId: string;
  groupKey: string;
  items: { columnSort: string | number; value: string; text: string }[];
}) {
  return request(`/inbiz/api/services/modelengine/v${InbizConfig.API_VERSION}/dictData`, {
    method: 'POST',
    data: params,
  });
}

// 子表存储查询
export async function getChildData(params: any) {
  return request(
    `/inbiz/api/services/modelengine/v${InbizConfig.API_VERSION}/business/selectDatas`,
    {
      method: 'POST',
      data: {
        name: params.storageConfig.name,
        data: {
          ref_id: params.inbiz?.queryData?.id,
          controlid: params.controlId,
        },
      },
    },
  );
}
